'''
Author: LHY 2601958675@qq.com
Date: 2023-07-06 17:52:10
LastEditors: LHY
LastEditTime: 2023-07-11 11:54:13
Description: bs4 学习
'''
from bs4 import BeautifulSoup

html = """
<ul>
<li><a href="zhangwuji.com">张无忌</a></li>
<li id="abc"><a href="zhouxingchi.com">周星驰</a></li>
<li><a href="zhubajie.com ">猪八戒</a></li>
<li><a href="wuzetian.com">武则天</a></li>
<a herf="jinmaoshiwang"> 哦哦</a>
</ul>
"""

#初始化butifulSoup 对象
page = BeautifulSoup(html,"html.parser")
result = page.find("li",attrs={"id":"abc"}) #找到一个 结果
# page.find_all()找到一堆结果|i
# result = page.find_all("li",attrs={"id":"abc"})

print(result)

a = result.find("a")
print(a)
print(a.text) #那文本
print(a.get("href")) #获取属性



resultall = page.find_all("li")

for i in resultall:
    b = i.find("a")
    text = b.text
    href = b.get("href")
    print(text,href)